nrow <- 200
n <- 1:nrow #initialising each vector to hold 200 spaces for all equations
f <- numeric(nrow)
p <- numeric(nrow)
approximation <- numeric(nrow)
difference <- numeric(nrow)
accuracy <- numeric(nrow)
#creating empty vectors for all sections
f[1]<- 1
f[2]<- 1
p[1]<- 1
p[2]<- 2
#declaring the first two of each fibonacci and pell numbers
#ChatGPT assisted me with this as I was struggling to get my equations to work
for (n in 3:nrow) { #fibonacci number equation
f[n] <- f[n-1] + f[n-2]
}
for (n in 3:nrow) { #pell number equation
p[n] <- 2*p[n-1] + p[n-2]
}
#creating the loop that generates the next 197 of each number
approximation[n] = (p[n] + p[n-1]) / p[n] #equation for the approximation
for (n in 2:nrow) {         #continuing the equation for the rest of the pell numbers
approximation[n] <- (p[n] + p[n-1]) / p[n]
}
approximation[1] <- 1 # declaration of the first approximation
square <- sqrt(2)#the actual square value
for (n in 1:nrow) { #loop to calculate the difference between the approximation and the sqrt
difference[n] <- round(approximation[n] - square, 5)
}
for (n in 1:nrow) { #equation for the accuracy between the two figures
acc <- 0
for (b in 0:15) { #checks how many figures match between the 1st and 15th figure
if (identical(round(approximation[n], b), round(square, b))) {
acc <- b
} else {
break #stops checking the figures if they don't match
}
}
accuracy[n] <- acc
}
pelldata <- data.frame(  #creation of the data frame
N = 1:nrow,
F = f,
P = p,
Approximation = approximation,
Difference = difference,
Accuracy = accuracy, #inputting all calculations and figures into the data frame
stringsAsFactors = FALSE
)
View(pelldata)
